package com.start_eternity.oasissafewalk.mapper;

import com.start_eternity.oasissafewalk.pojo.Order;
import com.start_eternity.oasissafewalk.pojo.Parent;
import com.start_eternity.oasissafewalk.pojo.dto.OrderDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * author:ZhangT
 * Date:2024 / 03 / 29 / 21:32
 * Description:
 */
public interface OrderMapper {

    //分页查询
    @Select("select * from `order` join student on `order`.s_id = student.s_id join parent on `order`.parent_id = parent.p_id")
    public List<OrderDTO> queryPage(@Param("page") int page, @Param("pageSize") int pageSize);

    //添加
    @Insert("insert into `order`(order_no, order_status, order_amount, pad, order_remark, parent_id," +
            "s_id, ctime, pickup_status, pay_channel, start_latitude, start_longitude, end_latitude, end_longitude) " +
            "values (#{orderNo},#{orderStatus},#{orderAmount},#{pad},#{orderRemark},#{parentId},#{sId}," +
            "#{ctime},#{pickupStatus},#{payChannel},#{startLatitude},#{startLongitude},#{endLatitude},#{endLongitude})")
    int insertOrder(Order order);

    //根据orderNo修改
    int updateOrderByNo(Order order);

    //根据orderId修改
    int updateOrderById(Order order);

    //根据orderNo查询订单
    @Select("select * from `order` where order_no = #{orderNo}")
    Order queryOrderByNo(@Param("orderNo") String orderNo);

    //根据orderId查询订单
    @Select("select * from `order` where order_id = #{orderId}")
    Order queryOrderById(@Param("orderId") Integer orderId);

    //根据order_no 查找 order_details的相关内容
    Order getDetails(@Param("orderNo") String orderNo);

    //根据order_no 查找 parent的相关内容
    Order getParent(@Param("orderNo") String orderNo);

    //获取订单必要信息DTO
    OrderDTO getInfo(@Param("orderNo") String orderNo);

}
